{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "import json\n",
    "import timeit\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9.77 s ± 136 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "g_file = \"/Users/zhangliye/julia_dev/GraphMLReader.jl/data/large_traffic_network.graphml\"\n",
    "%timeit G = nx.read_graphml( g_file )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "g_file = \"/Users/zhangliye/julia_dev/GraphMLReader.jl/data/large_traffic_network.graphml\"\n",
    "G = nx.read_graphml( g_file )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(109743, 379474)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(G.nodes), len(G.edges)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_path = '/Users/zhangliye/julia_dev/GraphMLReader.jl/data/origin.json'\n",
    "with open(file_path, 'r') as f:\n",
    "    origin_ids= json.load(f)\n",
    "len(origin_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "?time.clock"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "704 ms ± 4.83 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "703 ms ± 9.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "682 ms ± 7.49 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "700 ms ± 15 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "693 ms ± 11 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "711 ms ± 5.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "746 ms ± 22 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "712 ms ± 19.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "691 ms ± 5.29 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "679 ms ± 3.26 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "690 ms ± 2.31 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "712 ms ± 12.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "710 ms ± 3.44 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "691 ms ± 3.24 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "656 ms ± 4.05 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "718 ms ± 23.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "713 ms ± 18.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "717 ms ± 12.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "744 ms ± 24 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
      "752 ms ± 5.02 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "for id in origin_ids[:20]:\n",
    "    %timeit -r 1 path = nx.shortest_path(G, source=id, weight='length')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/anaconda3/envs/paper/lib/python3.7/site-packages/ipykernel_launcher.py:2: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
      "  \n",
      "/opt/anaconda3/envs/paper/lib/python3.7/site-packages/ipykernel_launcher.py:4: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
      "  after removing the cwd from sys.path.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.530352999999991\n",
      "1.925531000000035\n",
      "1.8018899999999576\n",
      "1.7358510000000251\n",
      "1.7658250000000066\n",
      "1.9203990000000317\n",
      "2.153090999999961\n",
      "1.3844940000000179\n",
      "1.757378000000017\n",
      "1.7155230000000188\n",
      "1.7743710000000306\n",
      "1.8871310000000108\n",
      "1.9668519999999603\n",
      "1.9600379999999973\n",
      "1.8716589999999655\n",
      "1.2840019999999868\n",
      "1.8503389999999627\n",
      "1.9865780000000086\n",
      "2.203350999999998\n",
      "2.3791239999999902\n"
     ]
    }
   ],
   "source": [
    "for id in origin_ids[:20]:\n",
    "    t0= time.clock()\n",
    "    path = nx.shortest_path(G, source=id, weight='length')\n",
    "    t1 = time.clock() - t0\n",
    "    print(t1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:paper] *",
   "language": "python",
   "name": "conda-env-paper-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
